* Module 3

use cses3orig, clear

*-------------------------------------------------------------------------------
* 1. Recoding of variables
*-------------------------------------------------------------------------------

tab C1004
gen cntelec=C1004
label var cntelec "Country-election"
tab cntelec

tab C1006_NAM
gen cntry=C1006_NAM
lab var cntry "Country"
tab cntry

tab C2005
recode C2005 2=0 1=1 7/9=., gen (unionm)
label var unionm "Union membership" 
lab def unionm 0 "Non-member" 1 "Member"
lab val unionm unionm
tab unionm

tab C2001
recode C2001 997/999=., gen (age)
label var age "Age" 
tab age

tab C2002
recode C2002 1=0 2=1 9=., gen (gender)
label var gender "Gender" 
lab def gender 0 "Male" 1 "Female"
lab val gender gender
tab gender

tab C2030
by cntry, sort: tab C2030 
recode C2030 1=1 2=2 3=3 4=4 8/9=., gen (locat)
label var locat "Location, rural-urban" 
lab def locat 1 "Village" 2 "Small/middle city" 3 "Suburbs" 4 "Large city"
lab val locat locat
tab locat

tab C2003
recode C2003 1/7=0 8=1 97/99=. , gen (educ)
replace educ=1 if (C2003==6 & cntry=="Ireland") /*IRL 2007 special code: 6=university degree*/ 
label var educ "Education, 2 cat" 
lab def educ 0 "Non-tertiary education" 1 "Tertiary education" 
lab val educ educ
tab educ

*-------------------------------------------------------------------------------
* 2. Social class
*-------------------------------------------------------------------------------

* 2.1 Recode occupation variable (clasdtprep), recode employment status (status)

recode C2011 96/99=. 01=3 10/13=6 20=4 21=5 22/24=4 30=4 31=5 32/33=4 34=6 40/43=3 50/53=1 61/62=2 70/84=2 90=2 91=1 92/94=2, gen (clasdtprep) 
label var clasdtprep "Social class preparation, detailed" 
lab def clasdtprep 1 "Service work" 2 "Prod work" 3 "Clerks" 4 "Socio-cultural" 5 "Technical" 6 "Managers"
lab val clasdtprep clasdtprep
tab clasdtprep

recode C2012 1/2=1 3/4=2 7/9=., gen (status)
replace status=1 if (C2012==5 & cntry=="Austria") | (C2012==5 & cntry=="Germany") | (C2012==5 & cntry=="Ireland") 
replace status=1 if C2012==6 & cntry=="Germany" 
replace status=. if C2012==6 & cntry=="Sweden" 
label var status "Employment status" 
lab def status 1 "Employed" 2"Self-employed"
lab val status status
tab status

* 2.2 Combine occupation and status

gen clasdt=.
replace clasdt=1 if clasdtprep==1 & status==1 /*Serv + employed = serv workers*/
replace clasdt=2 if clasdtprep==2 & status==1 /*Prod + employed = prod workers*/
replace clasdt=3 if clasdtprep==3 & status==1 /*Clerks + employed = clerks*/
replace clasdt=4 if clasdtprep==4 & status==1 /*Socio + employed = socio-cult professionals*/
replace clasdt=5 if clasdtprep==5 & status==1 /*Tech + employed = technical professionals*/
replace clasdt=6 if clasdtprep==6 & status==1 /*Manag + employed = managers*/
replace clasdt=7 if (clasdtprep==1 & status==2) | (clasdtprep==2 & status==2) | (clasdtprep==3 & status==2) /*working class occupation + self-employed=small business*/
replace clasdt=8 if (clasdtprep==4 & status==2) | (clasdtprep==5 & status==2) | (clasdtprep==6 & status==2) /*middle class occupation + self-employed=large empl/professional*/
label var clasdt "Social class, detailed" 
lab def clasdt 1"Service work" 2 "Prod work" 3 "Clerks" 4 "Socio-cultural" 5 "Technical" 6 "Managers" 7"Small business" 8"Large employers and self-employed prof"
lab val clasdt clasdt
tab clasdt


*-------------------------------------------------------------------------------
* 3. Voting behaviour - current election
*-------------------------------------------------------------------------------

* 3.1 Creation of party5A variable from C3023_LH_PL for all countries except Australia 

recode C3023_LH_PL (89/99=200), gen (party5A)

replace party5A=3 if inlist(C3023_LH_PL, 8) & cntelec=="FIN_2007" /*Finland 2007*/
replace party5A=2 if inlist(C3023_LH_PL, 2) & cntelec=="FIN_2007" /*Finland 2007*/
replace party5A=10 if inlist(C3023_LH_PL, 5) & cntelec=="FIN_2007" /*Finland 2007*/
replace party5A=11 if inlist(C3023_LH_PL, 4,9,17,19) & cntelec=="FIN_2007" /*Finland 2007*/
replace party5A=0 if !inlist(C3023_LH_PL, 2,4,5,9,17,19,8) & !missing(party5A) & party5A!=200 & cntelec=="FIN_2007" 
tab party5A if cntelec=="FIN_2007"
tab C3023_LH_PL if cntelec=="FIN_2007"

replace party5A=3 if inlist(C3023_LH_PL, 8) & cntelec=="FIN_2011" /*Finland 2011*/
replace party5A=2 if inlist(C3023_LH_PL, 1) & cntelec=="FIN_2011" /*Finland 2011*/
replace party5A=10 if inlist(C3023_LH_PL, 6) & cntelec=="FIN_2011" /*Finland 2011*/
replace party5A=11 if inlist(C3023_LH_PL, 7,9,11,12) & cntelec=="FIN_2011" /*Finland 2011*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,6,7,9,11,12,8) & !missing(party5A) & party5A!=200 & cntelec=="FIN_2011" 
tab party5A if cntelec=="FIN_2011"
tab C3023_LH_PL if cntelec=="FIN_2011"

replace party5A=3 if inlist(C3023_LH_PL, 7,8,21) & cntelec=="DEU_2005" /*Germany 2005*/
replace party5A=2 if inlist(C3023_LH_PL, 3) & cntelec=="DEU_2005" /*Germany 2005*/
replace party5A=10 if inlist(C3023_LH_PL, 5) & cntelec=="DEU_2005" /*Germany 2005*/
replace party5A=11 if inlist(C3023_LH_PL, 6,13,14,17,22) & cntelec=="DEU_2005" /*Germany 2005*/
replace party5A=0 if !inlist(C3023_LH_PL, 3,5,6,13,14,17,22,7,8,21) & !missing(party5A) & party5A!=200 & cntelec=="DEU_2005" 
tab party5A if cntelec=="DEU_2005"
tab C3023_LH_PL if cntelec=="DEU_2005"

replace party5A=3 if inlist(C3023_LH_PL, 7,8,16) & cntelec=="DEU_2009" /*Germany 2009*/
replace party5A=2 if inlist(C3023_LH_PL, 3) & cntelec=="DEU_2009" /*Germany 2009*/
replace party5A=10 if inlist(C3023_LH_PL, 5,12) & cntelec=="DEU_2009" /*Germany 2009*/
replace party5A=11 if inlist(C3023_LH_PL, 6,21) & cntelec=="DEU_2009" /*Germany 2009*/
replace party5A=0 if !inlist(C3023_LH_PL, 3,5,6,12,21,7,8,16) & !missing(party5A) & party5A!=200 & cntelec=="DEU_2009" 
tab party5A if cntelec=="DEU_2009"
tab C3023_LH_PL if cntelec=="DEU_2009"

replace party5A=3 if inlist(C3023_LH_PL, 4) & cntelec=="GRC_2009" /*Greece 2009*/
replace party5A=2 if inlist(C3023_LH_PL, 1) & cntelec=="GRC_2009" /*Greece 2009*/
replace party5A=10 if inlist(C3023_LH_PL, 6) & cntelec=="GRC_2009" /*Greece 2009*/
replace party5A=11 if inlist(C3023_LH_PL, 3,5) & cntelec=="GRC_2009" /*Greece 2009*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,3,5,6,4) & !missing(party5A) & party5A!=200 & cntelec=="GRC_2009" 
tab party5A if cntelec=="GRC_2009"
tab C3023_LH_PL if cntelec=="GRC_2009"

replace party5A=2 if inlist(C3023_LH_PL, 1) & cntelec=="ISL_2007" /*Iceland 2007*/
replace party5A=11 if inlist(C3023_LH_PL, 4) & cntelec=="ISL_2007" /*Iceland 2007*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,4) & !missing(party5A) & party5A!=200 & cntelec=="ISL_2007" 
tab party5A if cntelec=="ISL_2007"
tab C3023_LH_PL if cntelec=="ISL_2007"

replace party5A=2 if inlist(C3023_LH_PL, 1,10) & cntelec=="ISL_2009" /*Iceland 2009*/
replace party5A=11 if inlist(C3023_LH_PL, 4,8,9) & cntelec=="ISL_2009" /*Iceland 2009*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,4,8,9,10) & !missing(party5A) & party5A!=200 & cntelec=="ISL_2009" 
tab party5A if cntelec=="ISL_2009"
tab C3023_LH_PL if cntelec=="ISL_2009"

replace party5A=2 if inlist(C3023_LH_PL, 3) & cntelec=="IRL_2007" /*Ireland*/
replace party5A=10 if inlist(C3023_LH_PL, 4) & cntelec=="IRL_2007" /*Ireland*/
replace party5A=11 if inlist(C3023_LH_PL, 6,9,10,13) & cntelec=="IRL_2007" /*Ireland*/
replace party5A=0 if !inlist(C3023_LH_PL, 3,4,6,9,10,13) & !missing(party5A) & party5A!=200 & cntelec=="IRL_2007" 
tab party5A if cntelec=="IRL_2007"
tab C3023_LH_PL if cntelec=="IRL_2007"

replace party5A=3 if inlist(C3023_LH_PL, 9,13) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace party5A=2 if inlist(C3023_LH_PL, 2) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace party5A=10 if inlist(C3023_LH_PL, 4, 11) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace party5A=11 if inlist(C3023_LH_PL, 5) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace party5A=0 if !inlist(C3023_LH_PL, 2,4,11,5,9,13) & !missing(party5A) & party5A!=200 & cntelec=="NLD_2006" 
tab party5A if cntelec=="NLD_2006"
tab C3023_LH_PL if cntelec=="NLD_2006"

replace party5A=3 if inlist(C3023_LH_PL, 3,12) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace party5A=2 if inlist(C3023_LH_PL, 2) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace party5A=10 if inlist(C3023_LH_PL, 7,10) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace party5A=11 if inlist(C3023_LH_PL, 5) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace party5A=0 if !inlist(C3023_LH_PL, 2,5,7,10,3,12) & !missing(party5A) & party5A!=200 & cntelec=="NLD_2010" 
tab party5A if cntelec=="NLD_2010"
tab C3023_LH_PL if cntelec=="NLD_2010"

replace party5A=3 if inlist(C3023_LH_PL, 4) & cntelec=="NZL_2008" /*New Zealand*/
replace party5A=2 if inlist(C3023_LH_PL, 2) & cntelec=="NZL_2008" /*New Zealand*/
replace party5A=10 if inlist(C3023_LH_PL, 3) & cntelec=="NZL_2008" /*New Zealand*/
replace party5A=11 if inlist(C3023_LH_PL, 7,14,17) & cntelec=="NZL_2008" /*New Zealand*/
replace party5A=0 if !inlist(C3023_LH_PL, 2,3,7,14,17,4) & !missing(party5A) & party5A!=200 & cntelec=="NZL_2008" 
tab party5A if cntelec=="NZL_2008"
tab C3023_LH_PL if cntelec=="NZL_2008"

replace party5A=3 if inlist(C3023_LH_PL, 8) & cntelec=="NOR_2005" /*Norway 2005*/
replace party5A=2 if inlist(C3023_LH_PL, 3) & cntelec=="NOR_2005" /*Norway 2005*/
replace party5A=10 if inlist(C3023_LH_PL, 1) & cntelec=="NOR_2005" /*Norway 2005*/
replace party5A=11 if inlist(C3023_LH_PL, 2) & cntelec=="NOR_2005" /*Norway 2005*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,2,3,8) & !missing(party5A) & party5A!=200 & cntelec=="NOR_2005" 
tab party5A if cntelec=="NOR_2005"
tab C3023_LH_PL if cntelec=="NOR_2005"

replace party5A=3 if inlist(C3023_LH_PL, 8) & cntelec=="NOR_2009" /*Norway 2009*/
replace party5A=2 if inlist(C3023_LH_PL, 3) & cntelec=="NOR_2009" /*Norway 2009*/
replace party5A=10 if inlist(C3023_LH_PL, 1) & cntelec=="NOR_2009" /*Norway 2009*/
replace party5A=11 if inlist(C3023_LH_PL, 2) & cntelec=="NOR_2009" /*Norway 2009*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,2,3,8) & !missing(party5A) & party5A!=200 & cntelec=="NOR_2009" 
tab party5A if cntelec=="NOR_2009"
tab C3023_LH_PL if cntelec=="NOR_2009"

replace party5A=3 if inlist(C3023_LH_PL, 8) & cntelec=="SWE_2006" /*Sweden*/
replace party5A=2 if inlist(C3023_LH_PL, 2) & cntelec=="SWE_2006" /*Sweden*/
replace party5A=10 if inlist(C3023_LH_PL, 7,9) & cntelec=="SWE_2006" /*Sweden*/
replace party5A=11 if inlist(C3023_LH_PL, 1) & cntelec=="SWE_2006" /*Sweden*/
replace party5A=0 if !inlist(C3023_LH_PL, 1,2,7,9,8) & !missing(party5A) & party5A!=200 & cntelec=="SWE_2006" 
tab party5A if cntelec=="SWE_2006"
tab C3023_LH_PL if cntelec=="SWE_2006"


*3.2 Creation of party5B variable from B3005_1 for Australia 

recode C3023_LH_DC (90/99=200), gen (party5B)

replace party5B=2 if inlist(C3023_LH_DC, 2) & cntelec=="AUS_2007" /*Australia*/
replace party5B=10 if inlist(C3023_LH_DC, 4) & cntelec=="AUS_2007" /*Australia*/
replace party5B=0 if !inlist(C3023_LH_DC, 2,4) & !missing(party5B) & party5B!=200 & cntelec=="AUS_2007" 
tab party5B if cntelec=="AUS_2007"
tab C3023_LH_DC if cntelec=="AUS_2007"


*3.3 Merge of both variables in the new variable party5A

gen party5=party5A
replace party5=party5B if cntelec=="AUS_2007" 
label var party5 "Party choice, detailed"
lab def party5 0"Non-Left" 2"Social democrats" 3"Populists" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val party5 party5
tab party5


* 3.4 Turnout

tab C3021_1
recode C3021_1 1=1 5=2 7/9=3, gen (turnout)
label var turnout "Turnout" 
lab def turnout 1 "Voted" 2 "Not voted" 3 "Other"
lab val turnout turnout
tab turnout


* 3.5 Merge party and turnout: new variable party5abs

gen party5abs=party5
replace party5abs=4 if turnout==2 /*turnout: add a fourth category*/ 
replace party5abs=6 if turnout==3 /*other answer on turnout: add a sixth category*/ 
label var party5abs "Party choice with abstainers, detailed"
lab def party5abs 0"Non-Left" 2"Social democrats" 3"Populists" 4"Not voting" 6"Other turnout" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val party5abs party5abs
tab party5abs


*-------------------------------------------------------------------------------
* 4. Voting behaviour - previous election 
*-------------------------------------------------------------------------------

* 4.1 Creation of preparty5A variable from C3032_LH_PL for all countries except Australia 

recode C3032_LH_PL (89/99=200), gen (preparty5A)

replace preparty5A=3 if inlist(C3032_LH_PL, 8) & cntelec=="FIN_2007" /*Finland 2007*/
replace preparty5A=2 if inlist(C3032_LH_PL, 2) & cntelec=="FIN_2007" /*Finland 2007*/
replace preparty5A=10 if inlist(C3032_LH_PL, 5) & cntelec=="FIN_2007" /*Finland 2007*/
replace preparty5A=11 if inlist(C3032_LH_PL, 4,9,17,19) & cntelec=="FIN_2007" /*Finland 2007*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 2,4,5,9,17,19,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="FIN_2007" 
tab preparty5A if cntelec=="FIN_2007"
tab C3032_LH_PL if cntelec=="FIN_2007"

replace preparty5A=3 if inlist(C3032_LH_PL, 8) & cntelec=="FIN_2011" /*Finland 2011*/
replace preparty5A=2 if inlist(C3032_LH_PL, 1) & cntelec=="FIN_2011" /*Finland 2011*/
replace preparty5A=10 if inlist(C3032_LH_PL, 6) & cntelec=="FIN_2011" /*Finland 2011*/
replace preparty5A=11 if inlist(C3032_LH_PL, 7,9,11,12) & cntelec=="FIN_2011" /*Finland 2011*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,6,7,9,11,12,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="FIN_2011" 
tab preparty5A if cntelec=="FIN_2011"
tab C3032_LH_PL if cntelec=="FIN_2011"

replace preparty5A=3 if inlist(C3032_LH_PL, 7,8,21) & cntelec=="DEU_2005" /*Germany 2005*/
replace preparty5A=2 if inlist(C3032_LH_PL, 3) & cntelec=="DEU_2005" /*Germany 2005*/
replace preparty5A=10 if inlist(C3032_LH_PL, 5) & cntelec=="DEU_2005" /*Germany 2005*/
replace preparty5A=11 if inlist(C3032_LH_PL, 6,13,14,17,22) & cntelec=="DEU_2005" /*Germany 2005*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 3,5,6,13,14,17,22,7,8,21) & !missing(preparty5A) & preparty5A!=200 & cntelec=="DEU_2005" 
tab preparty5A if cntelec=="DEU_2005"
tab C3032_LH_PL if cntelec=="DEU_2005"

replace preparty5A=3 if inlist(C3032_LH_PL, 7,8,16) & cntelec=="DEU_2009" /*Germany 2009*/
replace preparty5A=2 if inlist(C3032_LH_PL, 3) & cntelec=="DEU_2009" /*Germany 2009*/
replace preparty5A=10 if inlist(C3032_LH_PL, 5,12) & cntelec=="DEU_2009" /*Germany 2009*/
replace preparty5A=11 if inlist(C3032_LH_PL, 6,21) & cntelec=="DEU_2009" /*Germany 2009*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 3,5,6,12,21,7,8,16) & !missing(preparty5A) & preparty5A!=200 & cntelec=="DEU_2009" 
tab preparty5A if cntelec=="DEU_2009"
tab C3032_LH_PL if cntelec=="DEU_2009"

replace preparty5A=3 if inlist(C3032_LH_PL, 4) & cntelec=="GRC_2009" /*Greece*/
replace preparty5A=2 if inlist(C3032_LH_PL, 1) & cntelec=="GRC_2009" /*Greece*/
replace preparty5A=10 if inlist(C3032_LH_PL, 6) & cntelec=="GRC_2009" /*Greece 2009*/
replace preparty5A=11 if inlist(C3032_LH_PL, 3,5) & cntelec=="GRC_2009" /*Greece 2009*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,3,5,6,4) & !missing(preparty5A) & preparty5A!=200 & cntelec=="GRC_2009" 
tab preparty5A if cntelec=="GRC_2009"
tab C3032_LH_PL if cntelec=="GRC_2009"

replace preparty5A=2 if inlist(C3032_LH_PL, 1) & cntelec=="ISL_2007" /*Iceland 2007*/
replace preparty5A=11 if inlist(C3032_LH_PL, 4) & cntelec=="ISL_2007" /*Iceland 2007*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,4) & !missing(preparty5A) & preparty5A!=200 & cntelec=="ISL_2007" 
tab preparty5A if cntelec=="ISL_2007"
tab C3032_LH_PL if cntelec=="ISL_2007"

replace preparty5A=2 if inlist(C3032_LH_PL, 1,10) & cntelec=="ISL_2009" /*Iceland 2009*/
replace preparty5A=11 if inlist(C3032_LH_PL, 4,8,9) & cntelec=="ISL_2009" /*Iceland 2009*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,4,8,9,10) & !missing(preparty5A) & preparty5A!=200 & cntelec=="ISL_2009" 
tab preparty5A if cntelec=="ISL_2009"
tab C3032_LH_PL if cntelec=="ISL_2009"

replace preparty5A=2 if inlist(C3032_LH_PL, 3) & cntelec=="IRL_2007" /*Ireland*/
replace preparty5A=10 if inlist(C3032_LH_PL, 4) & cntelec=="IRL_2007" /*Ireland*/
replace preparty5A=11 if inlist(C3032_LH_PL, 6,9,10,13) & cntelec=="IRL_2007" /*Ireland*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 3,4,6,9,10,13) & !missing(preparty5A) & preparty5A!=200 & cntelec=="IRL_2007" 
tab preparty5A if cntelec=="IRL_2007"
tab C3032_LH_PL if cntelec=="IRL_2007"

replace preparty5A=3 if inlist(C3032_LH_PL, 9,13) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace preparty5A=2 if inlist(C3032_LH_PL, 2) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace preparty5A=10 if inlist(C3032_LH_PL, 4, 11) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace preparty5A=11 if inlist(C3032_LH_PL, 5) & cntelec=="NLD_2006" /*Netherlands 2006*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 2,4,11,5,9,13) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NLD_2006" 
tab preparty5A if cntelec=="NLD_2006"
tab C3032_LH_PL if cntelec=="NLD_2006"

replace preparty5A=3 if inlist(C3032_LH_PL, 3,12) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace preparty5A=2 if inlist(C3032_LH_PL, 2) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace preparty5A=10 if inlist(C3032_LH_PL, 7,10) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace preparty5A=11 if inlist(C3032_LH_PL, 5) & cntelec=="NLD_2010" /*Netherlands 2010*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 2,5,7,10,3,12) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NLD_2010" 
tab preparty5A if cntelec=="NLD_2010"
tab C3032_LH_PL if cntelec=="NLD_2010"

replace preparty5A=3 if inlist(C3032_LH_PL, 4) & cntelec=="NZL_2008" /*New Zealand*/
replace preparty5A=2 if inlist(C3032_LH_PL, 2) & cntelec=="NZL_2008" /*New Zealand*/
replace preparty5A=10 if inlist(C3032_LH_PL, 3) & cntelec=="NZL_2008" /*New Zealand*/
replace preparty5A=11 if inlist(C3032_LH_PL, 7,14,17) & cntelec=="NZL_2008" /*New Zealand*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 2,3,7,14,17,4) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NZL_2008" 
tab preparty5A if cntelec=="NZL_2008"
tab C3032_LH_PL if cntelec=="NZL_2008"

replace preparty5A=3 if inlist(C3032_LH_PL, 8) & cntelec=="NOR_2005" /*Norway 2005*/
replace preparty5A=2 if inlist(C3032_LH_PL, 3) & cntelec=="NOR_2005" /*Norway 2005*/
replace preparty5A=10 if inlist(C3032_LH_PL, 1) & cntelec=="NOR_2005" /*Norway 2005*/
replace preparty5A=11 if inlist(C3032_LH_PL, 2) & cntelec=="NOR_2005" /*Norway 2005*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,2,3,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NOR_2005" 
tab preparty5A if cntelec=="NOR_2005"
tab C3032_LH_PL if cntelec=="NOR_2005"

replace preparty5A=3 if inlist(C3032_LH_PL, 8) & cntelec=="NOR_2009" /*Norway 2009*/
replace preparty5A=2 if inlist(C3032_LH_PL, 3) & cntelec=="NOR_2009" /*Norway 2009*/
replace preparty5A=10 if inlist(C3032_LH_PL, 1) & cntelec=="NOR_2009" /*Norway 2009*/
replace preparty5A=11 if inlist(C3032_LH_PL, 2) & cntelec=="NOR_2009" /*Norway 2009*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,2,3,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="NOR_2009" 
tab preparty5A if cntelec=="NOR_2009"
tab C3032_LH_PL if cntelec=="NOR_2009"

replace preparty5A=3 if inlist(C3032_LH_PL, 8) & cntelec=="SWE_2006" /*Sweden*/
replace preparty5A=2 if inlist(C3032_LH_PL, 2) & cntelec=="SWE_2006" /*Sweden*/
replace preparty5A=10 if inlist(C3032_LH_PL, 7,9) & cntelec=="SWE_2006" /*Sweden*/
replace preparty5A=11 if inlist(C3032_LH_PL, 1) & cntelec=="SWE_2006" /*Sweden*/
replace preparty5A=0 if !inlist(C3032_LH_PL, 1,2,7,9,8) & !missing(preparty5A) & preparty5A!=200 & cntelec=="SWE_2006" 
tab preparty5A if cntelec=="SWE_2006"
tab C3032_LH_PL if cntelec=="SWE_2006"


*4.2 Creation of preparty5B variable from C3032_LH_DC for Australia 

tab C3032_LH_DC
recode C3032_LH_DC (90/99=200), gen (preparty5B)

replace preparty5B=2 if inlist(C3032_LH_DC, 2) & cntelec=="AUS_2007" /*Australia*/
replace preparty5B=10 if inlist(C3032_LH_DC, 4) & cntelec=="AUS_2007" /*Australia*/
replace preparty5B=0 if !inlist(C3032_LH_DC, 2,4) & !missing(preparty5B) & preparty5B!=200 & cntelec=="AUS_2007" 
tab preparty5B if cntelec=="AUS_2007"
tab C3032_LH_DC if cntelec=="AUS_2007"


*4.3 Merge of both variables in the new variable preparty5A

tab preparty5A
tab1 preparty5A preparty5B

gen preparty5=preparty5A
replace preparty5=preparty5B if cntelec=="AUS_2007" 
label var preparty5 "preparty choice, detailed"
lab def preparty5 0"Non-Left" 2"Social democrats" 3"Populists" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val preparty5 preparty5
tab preparty5


*4.4 Pre-turnout

tab C3031
recode C3031 1=1 5=2 6=4 7/9=3, gen (preturnout)
label var preturnout "preturnout" 
lab def preturnout 1 "Voted" 2 "Not voted" 3 "Other" 4"Not eligible"
lab val preturnout preturnout
tab preturnout


*4.5 Merge preparty and preturnout: new variable preparty5abs

gen preparty5abs=preparty5
replace preparty5abs=4 if preturnout==2 /*turnout: add a fourth category*/ 
replace preparty5abs=5 if preturnout==4 /*not eligible: add a fifth category*/ 
replace preparty5abs=6 if preturnout==3 /*other answer on turnout: add a sixth category*/ 
label var preparty5abs "preparty choice with abstainers, detailed"
lab def preparty5abs 0"Non-Left" 2"Social democrats" 3"Populists" 4"Not voting" 5"Not eligible" 6"Other turnout" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val preparty5abs preparty5abs 
tab preparty5abs


*-------------------------------------------------------------------------------
* 5. Finalize the data set
*-------------------------------------------------------------------------------

keep cntry cntelec unionm age gender locat educ clasdtprep status clasdt party5 turnout party5abs preparty5 preturnout preparty5abs

save cses3_rec, replace 


